package com.test.daily.leetcode.y2022.m07.day0714.v01;

import java.util.PriorityQueue;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/7/14 上午 09:19
 * @version: 1.0
 */
public class Solution {
    public static void sortK(int[] arr, int K){
        PriorityQueue<Integer> pq = new PriorityQueue<>();
        int index = 0;
        for(; index<= Math.min(K-1, arr.length -1); index++){
            pq.add(arr[index]);
        }
        int i = 0;
        for(; index < arr.length; i++){
            arr[i] = pq.poll();
            pq.add(index++);
        }
        while(pq.size() != 0){
            arr[i++] = pq.poll();
        }
    }
}
